window.onload = (function() {
    // ----------------浏览器版本监控----要放最前面，以免不兼容语法影响执行-------------
    var userAgent = navigator.userAgent;
    // console.log(userAgent);
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
    var isIE11 = userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
    var Sys = {};
    var str = "你的浏览器版本太低了,已经和时代脱轨了，本系统已经不再支持微软IE内核浏览器 :(";
    var str2 = "推荐使用:<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:blue;'>谷歌</a>," + "<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E7%81%AB%E7%8B%90%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:blue;'>火狐</a>," + "<a target='_blank' style='color:blue; href='https://down.360safe.com/se/360se13.1.6000.0.exe'>360浏览器</a>" + "等其他主流浏览器,";
    var ua = navigator.userAgent.toLowerCase();
    if (isIE || isIE11) {
        document.writeln("<pre style='text-align:center;color:#fff;background-color:#195B40; height:100%;border:0;position:fixed;top:0;left:0;width:100%;z-index:1234'>" + "<h2 style='padding-top:200px;margin:0'><strong>" + str + "<br/></strong></h2><h2>" + str2 + "</h2><h2 style='margin:0'><strong>如果你的使用的是双核浏览器,请切换到极速模式访问...<br/></strong></h2></pre>");
        document.execCommand("Stop");
        //   alert("你目前的IE版本为" + Sys.ie + "版本太低，请升级！");
    } else if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([d.]+)/)[1];
        if (Sys.ie <= 7) {
            console.log("你目前的IE版本为" + Sys.ie + "版本太低，请升级！");
            // location.href = "http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie";
            document.writeln("<pre style='text-align:center;color:#fff;background-color:#195B40; height:100%;border:0;position:fixed;top:0;left:0;width:100%;z-index:1234'>" + "<h2 style='padding-top:200px;margin:0'><strong>" + str + "<br/></strong></h2><h2>" + str2 + "</h2><h2 style='margin:0'><strong>如果你的使用的是双核浏览器,请切换到极速模式访问...<br/></strong></h2></pre>");
            document.execCommand("Stop");
        }
    } else {
        // console.log(userAgent);
    }

    var sys2 = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/firefox\/([\d.]+)/)) ? (sys2.firefox = s[1]) : (s = ua.match(/chrome\/([\d.]+)/)) ? (sys2.chrome = s[1]) : (s = ua.match(/opera.([\d.]+)/)) ? (sys2.opera = s[1]) : (s = ua.match(/rv:([\d.]+)/)) ? (sys2.ie = s[1]) : (s = ua.match(/msie ([\d.]+)/)) ? (sys2.ie = s[1]) : (s = ua.match(/version\/([\d.]+).*safari/)) ? (sys2.safari = s[1]) : 0;
    var browser = "Unknown";
    var tip = document.createElement("div");
    var closeBtn = document.createElement("img");
    var contentHTML = "您当前使用的浏览器可能会出现界面显示异常或功能无法正常使用等问题，建议下载使用最新的 360 极速浏览器并切换到极速模式。";
    var endHTML = '&nbsp;&nbsp;&nbsp;&nbsp;<a href="../assets/360cse_13.0.2216.0.exe" target="_blank" style="cursor: pointer; color: red; font-weight: bold;">下载浏览器点我</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../views/speed-mode-tutorial.html" target="_blank" style="cursor: pointer; color: red; font-weight: bold;">不会切换到极速模式点我</a>';
    var handleClickClose = function(event) {
        document.body.removeChild(tip);
    };
    var startAppend = function() {
        document.body.appendChild(tip);
        tip.appendChild(closeBtn);
    };

    closeBtn.style.position = "absolute";
    closeBtn.style.right = "20px";
    closeBtn.style.bottom = "7px";
    closeBtn.style.cursor = "pointer";
    closeBtn.style.width = "15px";
    closeBtn.style.height = "15px";
    //   closeBtn.src = "../assets/images/icon-close.png";
    closeBtn.alt = "关闭";

    if (closeBtn.addEventListener) {
        closeBtn.addEventListener("click", handleClickClose);
    } else {
        // IE8 及以下
        closeBtn.attachEvent("onclick", handleClickClose);
    }

    tip.style.position = "relative";
    tip.style.backgroundColor = "yellow";
    tip.style.color = "red";
    tip.style.position = "fixed";
    tip.style.top = 0;
    tip.style.right = 0;
    tip.style.left = 0;
    tip.style.padding = "5px 20px";
    tip.style.fontSize = "14px";

    if (sys2.ie) {
        browser = "IE";
        tip.innerHTML = contentHTML + endHTML;
        startAppend();
    }
    if (sys2.firefox) {
        browser = "Firefox";
        tip.innerHTML = contentHTML + endHTML;
        startAppend();
    }
    if (sys2.chrome) {
        browser = "Chrome";
        var getChromeVersion = function() {
            var arr = navigator.userAgent.split(" ");
            var chromeVersion = "";
            for (var i = 0; i < arr.length; i++) {
                if (/chrome/i.test(arr[i])) chromeVersion = arr[i];
            }
            if (chromeVersion) {
                return Number(chromeVersion.split("/")[1].split(".")[0]);
            } else {
                return false;
            }
        };

        if (getChromeVersion()) {
            var version = getChromeVersion();
            // 如果 360 极速浏览器并切换到极速模式低于86版本
            if (version < 86) {
                tip.innerHTML = "您当前使用的浏览器版本过低，使用可能会出现界面显示异常或功能无法正常使用等问题，建议下载使用最新的 360 极速浏览器并切换到极速模式。" + endHTML;
                startAppend();
            }
        }
    }
    if (sys2.opera) {
        browser = "Opera";
        tip.innerHTML = contentHTML + endHTML;
        startAppend();
    }
    if (sys2.safari) {
        browser = "Safari";
    }
})();